﻿using System;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace Collab.Services.Remote.Entities
{
    [DataContract]
    public class User : INotifyPropertyChanged, IExtensibleDataObject, IEquatable<User>
    {
        [DataMember(Order = 1, IsRequired = true)]
        public Guid Id { get; private set; }
        [DataMember(Order = 2, IsRequired = true)]
        public string Name { get; private set; }
        [DataMember(Order = 3, IsRequired = true)]
        public UserStatus Status
        {
            get { return this.status; }
            set
            {
                if (this.status == value)
                    return;
                this.status = value;
                NotifyPropertyChanged("Status");
            }
        }
        private UserStatus status;

        public User(string name, string activeFile)
        {
            this.Id = Guid.NewGuid();
            this.Name = name;
            this.status = new UserStatus(this.Id, "");
        }

        public Tuple<byte,byte,byte> Color { get; set; }

        public string ColorString
        {
            get
            {
                return "#FF" + Color.Item1 + Color.Item2 + Color.Item3; 
            }
        }

        public override bool Equals(object obj)
        {
            return obj != null && GetType() == obj.GetType() && this.Id.Equals(obj);
        }

        public override int GetHashCode()
        {
            return this.Id.GetHashCode();
        }


        #region IExtensibleDataObject Members

        public ExtensionDataObject ExtensionData { get; set; }

        #endregion

        protected void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;


        #region IEquatable<User> Members

        public bool Equals(User other)
        {
            return this.Id == other.Id && this.Name == other.Name && this.Status == other.Status;
        }

        #endregion
    }
}
